/* 自己手写 */
function* generatorFn() {
    let v1 = yield new Promise((resolve) => {
        setTimeout(() => {
            resolve(1)
        }, 200);
    })
    let v2 = yield new Promise((resolve) => {
        setTimeout(() => {
            resolve(1)
        }, 200);
    })
    return v1 + v2
}
function asyncToGenerator(generatorFn) {
    let gen = generatorFn()
    return new Promise((resolve, reject) => {
        let recusion = ({ value, done }) => {
            if (done) {
                resolve(value)
            } else {
                Promise.resolve(value).then(res => {
                    recusion(gen.next(res))
                }, (error) => {
                    reject(error)
                })
            }
        }
        try {
            recusion(gen.next())
        } catch (error) {
            reject(error)
        }
    })

}
asyncToGenerator(generatorFn).then(res => {
    console.log('res', res)
})